import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // 用于存储用户登录的信息
    email: null,
    uid: sessionStorage.getItem('UserID') ? sessionStorage.getItem('UserID') : null,
    uname: sessionStorage.getItem('Uname') ? sessionStorage.getItem('Uname') : null,
    haveOrder: false,
    // 存储token
    token: sessionStorage.getItem('token') ? sessionStorage.getItem('token') : '',
    // 存储选中的联系人ID
    linkManID: null,
  },
  getters: {},
  mutations: {
    updatalinkManID(state,linkManID) {
      state.linkManID=linkManID
    },

    updataEmail(state, email) {
      state.email = email;
      // console.log('用户邮箱更新为:', email)
    },
    updataUid(state, uid) {
      state.uid = uid;
      // console.log('用户ID更新为:', uid)
    },
    updataUname(state, uname) {
      state.uname = uname;
      // console.log('用户名更新为:', uname)
    },
    updataHaveOrder(state, haveOrder) {
      state.haveOrder = haveOrder;
      // console.log('查到订单数量为:', haveOrder)
    },
    // 修改token，并将token存入localStorage
    changeToken(state, token) {
      state.token = token;
      localStorage.setItem('token', token);
    },
  },
  actions: {},
  modules: {},
});
